<?php require_once("includes/config.php"); 
  
  if($_SERVER["REQUEST_METHOD"] == "POST")
  {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $username =$_POST['username'];
    $email = $_POST['email'];
    $pass = sha1($_POST['password']);
    $rows= query("SELECT * FROM apartments_owner WHERE username = ? or email =?  ",$username,$email);
    
    if(!empty($rows))
    {
      $row = $rows[0];
      if($row["email"] == $email && $row["username"] == $username)
      {
        $message = $username . " و".$email ." موجودان بالفعل" ;
      }
      else if($row["username"] == $username)
      {
       $message = $username . " موجود بالفعل" ;
      }
      else if($row["email"] == $email)
      {
        $message = $email . " موجود بالفعل" ;
      }
      render("register.php", array("title" => "تسجيل","message"=>$message));
    }
    else
    {
      $result = query("INSERT INTO apartments_owner (first_name, last_name, username, email,password) VALUES (?, ?, ?, ?, ? ) ", 
      $firstname,$lastname,$username,$email,$pass);
      //start session
      echo "تم";
    }
  }
  
  else
   render("register.php", array("title" => "تسجيل"));
   
?>